package com.gxuwz.hmr.project.system.classify.controller;

import java.util.List;

import com.gxuwz.hmr.project.system.classify.domain.Classify;
import com.gxuwz.hmr.project.system.classify.service.IClassifyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.classify.domain.Classify;
import com.ruoyi.project.system.classify.service.IClassifyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 慢病分类管理Controller
 * 
 * @author ruoyi
 * @date 2021-05-05
 */
@Controller
@RequestMapping("/system/classify")
public class ClassifyController extends BaseController
{
    private String prefix = "system/classify";

    @Autowired
    private IClassifyService classifyService;

    @RequiresPermissions("system:classify:view")
    @GetMapping()
    public String classify()
    {
        return prefix + "/classify";
    }

    /**
     * 查询慢病分类管理列表
     */
    @RequiresPermissions("system:classify:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Classify classify)
    {
        startPage();
        List<Classify> list = classifyService.selectClassifyList(classify);
        return getDataTable(list);
    }

    /**
     * 导出慢病分类管理列表
     */
    @RequiresPermissions("system:classify:export")
    @Log(title = "慢病分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Classify classify)
    {
        List<Classify> list = classifyService.selectClassifyList(classify);
        ExcelUtil<Classify> util = new ExcelUtil<Classify>(Classify.class);
        return util.exportExcel(list, "慢病分类管理数据");
    }

    /**
     * 新增慢病分类管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存慢病分类管理
     */
    @RequiresPermissions("system:classify:add")
    @Log(title = "慢病分类管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Classify classify)
    {
        return toAjax(classifyService.insertClassify(classify));
    }

    /**
     * 修改慢病分类管理
     */
    @GetMapping("/edit/{classifyId}")
    public String edit(@PathVariable("classifyId") Long classifyId, ModelMap mmap)
    {
        Classify classify = classifyService.selectClassifyById(classifyId);
        mmap.put("classify", classify);
        return prefix + "/edit";
    }

    /**
     * 修改保存慢病分类管理
     */
    @RequiresPermissions("system:classify:edit")
    @Log(title = "慢病分类管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Classify classify)
    {
        return toAjax(classifyService.updateClassify(classify));
    }

    /**
     * 删除慢病分类管理
     */
    @RequiresPermissions("system:classify:remove")
    @Log(title = "慢病分类管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(classifyService.deleteClassifyByIds(ids));
    }
}
